package com.another.bidservice.controller;

import com.another.bidservice.entity.TCodeCur;
import com.another.bidservice.entity.TCodeRule;
import com.another.bidservice.service.ICodeCurService;
import com.another.common.utils.common.MyException;
import org.apache.log4j.Logger;
import com.another.common.utils.result.Result;
import com.another.common.utils.result.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/codecur")
@CrossOrigin
public class CodeCurController {

    private Logger logger=Logger.getLogger(this.getClass());

    @Autowired
    private ICodeCurService iCodeCurService;



    @PostMapping(value = "/getList")
    @ResponseBody
    public Result getList(@RequestBody TCodeCur tCodeCur) {
       try {
            return iCodeCurService.getList(tCodeCur);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    @PostMapping(value = "/deleteList")
    @ResponseBody
    public Result deleteList(@RequestBody List<Integer> rowids) {
        try {
            return iCodeCurService.deleteList(rowids);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    @PostMapping(value = "/insertList")
    @ResponseBody
    public Result insertList(@RequestBody List<TCodeCur> tCodeCurs) {
        try {
            return iCodeCurService.insertList(tCodeCurs);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    @PostMapping(value = "/updateList")
    @ResponseBody
    public Result updateList(@RequestBody List<TCodeCur> tCodeCurs) {
        try {
            return iCodeCurService.updateList(tCodeCurs);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }
    
    @PostMapping(value = "/updateCodeCur")
    @ResponseBody
    public Result updateCodeCur(@RequestBody TCodeCur tCodeCur) {
        try {
            return iCodeCurService.updateCodeCur(tCodeCur);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    @PostMapping(value = "/insertCodeCur")
    @ResponseBody
    public Result insertCodeCur(@RequestBody TCodeCur tCodeCur) {
        try {
            return iCodeCurService.insertCodeCur(tCodeCur);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    @PostMapping(value = "/deleteCodeCur")
    @ResponseBody
    public Result deleteCodeCur(@RequestBody TCodeCur tCodeCur) {
        try {
            return iCodeCurService.deleteCodeCur(tCodeCur);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    /**
     * @param codeRule
     * @return com.another.exhibitioncommon.utils.result.Result
     * @author Another
     * @description :  生成编号序列号取值表
     * @date 2019/10/23 11:19:52
     * @version : 1.0
     */
    @PostMapping(value = "/generatedNumber")
    @ResponseBody
    public Result generatedNumber(@RequestBody TCodeRule codeRule) {
        try {
            return iCodeCurService.generatedNumber(codeRule);
        } catch (MyException me) {
            logger.info(me.getMessage(), me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(), e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }
}



